package jpb.module.dao.manager;

import jpb.module.dao.manager.mapper.ManagerMapper;
import jpb.module.daomain.manager.Manager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by haol on 2017/3/14.
 * 组织管理者
 */
@Repository
public class ManagerDao {

        private Logger logger = LoggerFactory.getLogger(ManagerDao.class);

        @Autowired
        private ManagerMapper mapper;

        public void delete(int id) {
                try {
                        mapper.delete(id);
                } catch (Exception e) {
                        e.printStackTrace();
                        logger.error(e.getMessage());
                }
        }

        public void updateInfo(Manager manager) {
                try {
                        mapper.update(manager);
                } catch (Exception e) {
                        e.printStackTrace();
                        logger.error(e.getMessage());
                }
        }
        public void updatePwd(Manager manager) {
                try {
                        mapper.updatePwd(manager);
                } catch (Exception e) {
                        e.printStackTrace();
                        logger.error(e.getMessage());
                }
        }


        public Manager getByAccount(String account) {
                try {
                        return mapper.getByAccount(account);
                } catch (Exception e) {
                        e.printStackTrace();
                        logger.error(e.getMessage());
                        return null;
                }
        }

        public void updateLoginTime(Manager manager) {
                try {
                        mapper.updateLoginTime(manager);
                } catch (Exception e) {
                        e.printStackTrace();
                        logger.error(e.getMessage());
                }
        }

        public void updateTime(String id,String time) {
                try {
                        mapper.updateTime(id,time);
                } catch (Exception e) {
                        e.printStackTrace();
                        logger.error(e.getMessage());
                }
        }
        public void add(Manager manager) {
                try {
                        mapper.add(manager);
                } catch (Exception e) {
                        logger.error(e.getMessage());
                }
        }
        public void updateHead(Manager manager){
                try{
                        mapper.updateHead(manager);
                }catch (Exception e){
                        logger.error(e.getMessage());
                }
        }
        public List<Manager> getByOid(String oid) {
                try {
                        return mapper.getByOid(oid);
                } catch (Exception e) {
                        logger.error(e.getMessage());
                        return null;
                }
        }
        public Manager get(String id) {
                try {
                        return mapper.get(id);
                } catch (Exception e) {
                        logger.error(e.getMessage());
                        return null;
                }
        }
//        public Manager getByOidMid(String oid,String mid){
//                try {
//                        return mapper.getByOidMid(oid,mid);
//                } catch (Exception e) {
//                        logger.error(e.getMessage());
//                        return null;
//                }
//        }
        public Manager getFounder(String oid){
                try {
                        return mapper.getFounder(oid);
                } catch (Exception e) {
                        logger.error(e.getMessage());
                        return null;
                }
        }
}
